// todo typescript 类型配置
export function wrapAsyncWithLoading (vm: Vue | any, loadingkey: string, methodKey: string | string[]) {
  if (Array.isArray(methodKey)) {
    methodKey.forEach(oneMethodKey => wrapAsyncWithLoading(vm, loadingkey, oneMethodKey))
    return
  }
  const pre = (vm[methodKey] as Function).bind(vm)
  vm[methodKey] = (...args: unknown[]) => {
    vm[loadingkey] = true
    return pre(...args).finally(() => {
      vm[loadingkey] = false
    })
  }
}

export function sleep (seconds: number) {
  return new Promise(resolve => {
    setTimeout(resolve, seconds * 1000)
  })
}
